package Chuong07;

import java.io.*;
public class Bai11 {

	private static FileWriter fW;
	private static BufferedWriter bW;
	String filename = "D:/Hoc Tap/Hoc Ki VII/Chuyen De Java/OnTap_Code/OnTap/src/Chuong07/File/songuyento.dat";
	//String filename = "Z:/songuyento.dat";
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	
	public static boolean IsNguyenTo(int n){
		boolean resuft = true;
		if(n >= 2){
			for(int i = 2; i < n; i++){
				if(n % i == 0) resuft = false;
			}
		}
		else resuft = false;
		return resuft;
	}	
	
	public Bai11(){
		try{
			fW = new FileWriter(filename);
			bW = new BufferedWriter(fW);
			System.out.print("Nhập n = ");
			int n = Integer.parseInt(in.readLine());
			if(n >= 2){
				int i = 3, j = 1;
				String line = "2";
				
				while(i <= n){
					if(IsNguyenTo(i)){
						line += "-" + i;
						j++;
					}
					i++;
				}
				bW.write(j + "");
				bW.newLine();
				bW.write(line);
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try { 
			bW.close();
			fW.close(); 
		} 
		catch (IOException e) { 
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Bai11();
	}

}
